using System;
using System.Reflection;
using CommandSystem;

namespace CustomItem.Commands.CustomItemCommands
{
    public class List : ICommand
    {
        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            if (!sender.CheckPermission(PlayerPermissions.GivingItems))
            {
                response = "你没有权限使用此命令！";
                return false;
            }

            response = "所有可用的自定义物品列表：";
            foreach (var item in CustomItemPlugin.Instance.Manager.AllTypes.Keys)
            {
                var attr = item.GetCustomAttribute<ItemInfoAttribute>();
                response += $"\n{attr.Name} ({item.Name})";
            }

            return true;
        }

        public string Command { get; } = "list";
        public string[] Aliases { get; } = Array.Empty<string>();
        public string Description { get; } = "获取插件物品列表";
    }
}